package org.nfyszny.zzzs.modules.controller;

import java.util.Arrays;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoDict;
import org.jeecg.common.system.query.QueryGenerator;
import org.nfyszny.zzzs.modules.entity.ZzzsRecordingOfProductionCapacity;
import org.nfyszny.zzzs.modules.service.IZzzsRecordingOfProductionCapacityService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;

/**
 * @Description: 生产能力备案
 * @Author: jeecg-boot
 * @Date: 2022-11-11
 * @Version: V1.0
 */
@Api(tags = "生产能力备案")
@RestController
@RequestMapping("/modules/zzzsRecordingOfProductionCapacity")
@Slf4j
public class ZzzsRecordingOfProductionCapacityController extends JeecgController<ZzzsRecordingOfProductionCapacity, IZzzsRecordingOfProductionCapacityService> {
    @Autowired
    private IZzzsRecordingOfProductionCapacityService zzzsRecordingOfProductionCapacityService;

    /**
     * 变更
     * @param zzzsRecordingOfProductionCapacity
     * @return
     */
    @AutoLog(value = "生产能力备案-修改备案")
    @ApiOperation(value="生产能力备案-修改备案", notes="生产能力备案-修改备案")
    //@RequiresPermissions("org.nfyszny.zzzs:zzzs_record_of_supply_ability:delete")
    @PutMapping(value = "/change")
    public Result<String> change(@RequestBody ZzzsRecordingOfProductionCapacity zzzsRecordingOfProductionCapacity) {
        zzzsRecordingOfProductionCapacityService.change(zzzsRecordingOfProductionCapacity);
        return Result.TOK("删除成功!");
    }

    /**
     * 年审
     * @param zzzsRecordingOfProductionCapacity
     * @return
     */
    @AutoLog(value = "生产能力备案-修改备案")
    @ApiOperation(value="生产能力备案-修改备案", notes="生产能力备案-修改备案")
    //@RequiresPermissions("org.nfyszny.zzzs:zzzs_record_of_supply_ability:delete")
    @PutMapping(value = "/review")
    public Result<String> review(@RequestBody ZzzsRecordingOfProductionCapacity zzzsRecordingOfProductionCapacity) {
        zzzsRecordingOfProductionCapacityService.review(zzzsRecordingOfProductionCapacity);
        return Result.TOK("删除成功!");
    }

    /**
     * 根据id获取状态
     * @param productId
     * @return
     */
    @ApiOperation(value = "生产能力备案-获取状态", notes = "生产能力备案-获取状态")
    @GetMapping(value = "/getRecordStatus/{productId}")
    public Result getRecordStatus(@PathVariable("productId") String productId) {
        Map<String, Object> map = zzzsRecordingOfProductionCapacityService.getState(productId);
        return Result.TOK(map);
    }
    /**
     * getHaveInfoById
     */
    @ApiOperation(value = "生产能力备案-查询已备案完成的备案信息", notes = "生产能力备案-查询已备案完成的备案信息")
    @GetMapping(value = "/getHaveInfoById")
    public Result<ZzzsRecordingOfProductionCapacity> getHaveInfoById(@RequestParam(name = "id", required = true) String id) {
        ZzzsRecordingOfProductionCapacity zzzsRecordingOfProductionCapacity = zzzsRecordingOfProductionCapacityService.getHaveInfoById(id);
        if (zzzsRecordingOfProductionCapacity == null) {
            return Result.error("未找到对应数据");
        }
        return Result.TOK(zzzsRecordingOfProductionCapacity);
    }

    /**
     * 分页列表查询
     *
     * @param zzzsRecordingOfProductionCapacity
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    //@AutoLog(value = "生产能力备案-分页列表查询")
    @ApiOperation(value = "生产能力备案-分页列表查询", notes = "生产能力备案-分页列表查询")
    @GetMapping(value = "/list")
    public Result<IPage<ZzzsRecordingOfProductionCapacity>> queryPageList(ZzzsRecordingOfProductionCapacity zzzsRecordingOfProductionCapacity,
                                                                          @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                                          @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                                          HttpServletRequest req) {
        QueryWrapper<ZzzsRecordingOfProductionCapacity> queryWrapper = QueryGenerator.initQueryWrapper(zzzsRecordingOfProductionCapacity, req.getParameterMap());
        Page<ZzzsRecordingOfProductionCapacity> page = new Page<ZzzsRecordingOfProductionCapacity>(pageNo, pageSize);
        IPage<ZzzsRecordingOfProductionCapacity> pageList = zzzsRecordingOfProductionCapacityService.page(page, queryWrapper);
        return Result.TOK(pageList);
    }

    /**
     * 分页列表查询
     *
     * @param zzzsRecordingOfProductionCapacity
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    //@AutoLog(value = "生产能力备案-分页列表查询")
    @ApiOperation(value = "生产能力备案-根据产品id分页列表查询", notes = "生产能力备案-根据产品id分页列表查询")
    @GetMapping(value = "/getListByProductId")
    @AutoDict
    public Result<IPage<ZzzsRecordingOfProductionCapacity>> getListByProductId(ZzzsRecordingOfProductionCapacity zzzsRecordingOfProductionCapacity,
                                                                               @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                                               @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                                               HttpServletRequest req) {
        QueryWrapper<ZzzsRecordingOfProductionCapacity> queryWrapper = QueryGenerator.initQueryWrapper(zzzsRecordingOfProductionCapacity, req.getParameterMap());
        Page<ZzzsRecordingOfProductionCapacity> page = new Page<ZzzsRecordingOfProductionCapacity>(pageNo, pageSize);
        IPage<ZzzsRecordingOfProductionCapacity> pageList = zzzsRecordingOfProductionCapacityService.getListByProductId(queryWrapper, page);

        return Result.TOK(pageList);
    }

    /**
     * 添加
     *
     * @param zzzsRecordingOfProductionCapacity
     * @return
     */
    @AutoLog(value = "生产能力备案-添加")
    @ApiOperation(value = "生产能力备案-添加", notes = "生产能力备案-添加")
    //@RequiresPermissions("org.nfyszny.zzzs:zzzs_recording_of_production_capacity:add")
    @PostMapping(value = "/add")
    public Result<String> add(@RequestBody ZzzsRecordingOfProductionCapacity zzzsRecordingOfProductionCapacity) {
        zzzsRecordingOfProductionCapacityService.saveRecordingOfProductionCapacity(zzzsRecordingOfProductionCapacity);
        return Result.TOK("添加成功！");
    }

    /**
     * 提交生产能力备案
     *
     * @param
     * @return
     */
    @AutoLog(value = "供货能力备案-提交供货能力备案")
    @ApiOperation(value = "供货能力备案-提交供货能力备案", notes = "供货能力备案-提交供货能力备案")
    //@RequiresPermissions("org.nfyszny.zzzs:zzzs_record_of_supply_ability:add")
    @PostMapping(value = "/submitRecord")
    public Result<String> submitRecord(@RequestBody ZzzsRecordingOfProductionCapacity zzzsRecordingOfProductionCapacity) {
        System.out.println("zzzsRecordingOfProductionCapacity = " + zzzsRecordingOfProductionCapacity);
        zzzsRecordingOfProductionCapacityService.submitRecord(zzzsRecordingOfProductionCapacity);
        return Result.TOK("添加成功！");
    }

    /**
     * 编辑
     *
     * @param zzzsRecordingOfProductionCapacity
     * @return
     */
    @AutoLog(value = "生产能力备案-编辑")
    @ApiOperation(value = "生产能力备案-编辑", notes = "生产能力备案-编辑")
    //@RequiresPermissions("org.nfyszny.zzzs:zzzs_recording_of_production_capacity:edit")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
    public Result<String> edit(@RequestBody ZzzsRecordingOfProductionCapacity zzzsRecordingOfProductionCapacity) {
        zzzsRecordingOfProductionCapacityService.updateById(zzzsRecordingOfProductionCapacity);
        return Result.TOK("编辑成功!");
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "生产能力备案-通过id删除")
    @ApiOperation(value = "生产能力备案-通过id删除", notes = "生产能力备案-通过id删除")
    //@RequiresPermissions("org.nfyszny.zzzs:zzzs_recording_of_production_capacity:delete")
    @DeleteMapping(value = "/delete")
    public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
        zzzsRecordingOfProductionCapacityService.removeById(id);
        return Result.TOK("删除成功!");
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "生产能力备案-批量删除")
    @ApiOperation(value = "生产能力备案-批量删除", notes = "生产能力备案-批量删除")
    //@RequiresPermissions("org.nfyszny.zzzs:zzzs_recording_of_production_capacity:deleteBatch")
    @DeleteMapping(value = "/deleteBatch")
    public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        this.zzzsRecordingOfProductionCapacityService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.TOK("批量删除成功!");
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    //@AutoLog(value = "生产能力备案-通过id查询")
    @ApiOperation(value = "生产能力备案-通过id查询", notes = "生产能力备案-通过id查询")
    @GetMapping(value = "/queryById")
    public Result<ZzzsRecordingOfProductionCapacity> queryById(@RequestParam(name = "id", required = true) String id) {
        ZzzsRecordingOfProductionCapacity zzzsRecordingOfProductionCapacity = zzzsRecordingOfProductionCapacityService.getById(id);
        if (zzzsRecordingOfProductionCapacity == null) {
            return Result.error("未找到对应数据");
        }
        return Result.TOK(zzzsRecordingOfProductionCapacity);
    }

    /**
     * 导出excel
     *
     * @param request
     * @param zzzsRecordingOfProductionCapacity
     */
    //@RequiresPermissions("org.nfyszny.zzzs:zzzs_recording_of_production_capacity:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, ZzzsRecordingOfProductionCapacity zzzsRecordingOfProductionCapacity) {
        return super.exportXls(request, zzzsRecordingOfProductionCapacity, ZzzsRecordingOfProductionCapacity.class, "生产能力备案");
    }

    /**
     * 通过excel导入数据
     *
     * @param request
     * @param response
     * @return
     */
    //@RequiresPermissions("zzzs_recording_of_production_capacity:importExcel")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, ZzzsRecordingOfProductionCapacity.class);
    }

}
